//
//  ViewController.swift
//  1.20.Loading Web Pages with UIWebView
//
//  Created by joker on 15/7/22.
//  Copyright (c) 2015年 joker. All rights reserved.
//

import UIKit

class ViewController: UIViewController , UIWebViewDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        /* #1 */
        //        let webView = UIWebView(frame: view.bounds)
//        let htmlString = "<br/>iOS <strong>Programming</strong>"
//        webView.loadHTMLString(htmlString, baseURL: nil)
//        view.addSubview(webView)
        
        var frame = view.bounds
        frame.origin.y = UIApplication.sharedApplication().statusBarFrame.height
        frame.size.height -= frame.origin.y
        
        let webView = UIWebView(frame: frame)
        webView.delegate = self
        webView.scalesPageToFit = true
        view.addSubview(webView)
        
        let url = NSURL(string: "http://www.apple.com")
        let request = NSURLRequest(URL: url!)
        
        webView.loadRequest(request)
        
        view.addSubview(webView)
    }

    
    func webViewDidStartLoad(webView: UIWebView) {
        UIApplication.sharedApplication().networkActivityIndicatorVisible = true
    }
    func webViewDidFinishLoad(webView: UIWebView) {
        UIApplication.sharedApplication().networkActivityIndicatorVisible = false
    }
    func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
        UIApplication.sharedApplication().networkActivityIndicatorVisible = false
    }
}

